<?php
//连接数据库
require_once('conn.php');
class User{
    private $nenufish_user_id;                  //用户ID
    private $nenufish_user_name;                //用户姓名
    private $nenufish_user_pic;                 //用户头像
    private $nenufish_user_skill;               //用户可以提供帮助的技能类型
    private $nenufish_user_skillOfferState;     //用户现在提供服务的状态
    private $nenufish_user_updateUserName;      //更改的用户名
    private $nenufish_user_updateUserPic;       //更改的用户头像
    private $nenufish_user_updateSkill;         //更改的用户提供技能类型
    private $nenufish_user_updateUserState;     //更改的用户状态
    private $nenufish_user_psw;                 //用户密码
    private $nenufish_user_updatePsw;           //更改的用户密码
    private $nenufish_user_taskId;              //单号

    //通过用户ID查询用户所有数据
    public function getAllById($nenufish_user_id){
        $sql = "SELECT *
                FROM db_nenufish.db_nenufish_user
                WHERE nenufish_user_id = '".$nenufish_user_id."'";
        $query = mysqli_query($GLOBALS['link'],$sql) ;
        return $query;
    }

    //查询用户发布的所有任务
    public function getAllTask1($nenufish_user_id){
        $sql = "SELECT *
                FROM db_nenufish.db_nenufish_task,db_nenufish.db_nenufish_skillfind
                WHERE nenufish_task_findUser = ".$nenufish_user_id ."
                       AND nenufish_task_skillfindId = nenufish_skillFind_id";
        $query = mysqli_query($GLOBALS['link'],$sql);
        return $query;
    }

    //查询用户提供技能的所有任务
    public function getAllTask2($nenufish_user_id){
        $sql = "SELECT *
                FROM db_nenufish.db_nenufish_task,db_nenufish.db_nenufish_skilloffer
                WHERE nenufish_task_offerUser = ".$nenufish_user_id ."
                       AND nenufish_task_skillofferId = nenufish_skillOffer_id";
        $query = mysqli_query($GLOBALS['link'],$sql);
        return $query;
    }

    //查询未完成的任务
    //发布的任务
    public function getDoingTask1($nenufish_user_id){
        $sql = "SELECT *
                FROM db_nenufish.db_nenufish_task,db_nenufish.db_nenufish_skillfind
                WHERE nenufish_task_findUser = ".$nenufish_user_id." AND nenufish_task_state = '3' AND nenufish_task_skillfindId = nenufish_skillFind_id";
        $query = mysqli_query($GLOBALS['link'],$sql);
        return $query;
    }
    //提供技能的任务
    public function getDoingTask2($nenufish_user_id){
        $sql = "SELECT *
                FROM db_nenufish.db_nenufish_task,db_nenufish.db_nenufish_skilloffer
                WHERE nenufish_task_offerUser = ".$nenufish_user_id." AND nenufish_task_state = '1' AND nenufish_task_skillofferId = nenufish_skillOffer_id";
        $query = mysqli_query($GLOBALS['link'],$sql);
        return $query;
    }

    //查询未支付的任务
    public function getUnpayTask($nenufish_user_id){
        $sql = "SELECT *
                FROM db_nenufish.db_nenufish_task,db_nenufish.db_nenufish_skillfind
                WHERE nenufish_task_findUser = ".$nenufish_user_id."  AND nenufish_task_state = '4' AND nenufish_task_skillfindId = nenufish_skillFind_id";
        $query = mysqli_query($GLOBALS['link'],$sql);
        return $query;
    }

    //查询未确认的任务
    //发布需求
    public function getUnconfirmTask1($nenufish_user_id){
        $sql = "SELECT *
                FROM db_nenufish.db_nenufish_task,db_nenufish.db_nenufish_skillfind
                WHERE nenufish_task_findUser = ".$nenufish_user_id." AND nenufish_task_state = '2' AND nenufish_task_skillfindId = nenufish_skillFind_id";
        $query = mysqli_query($GLOBALS['link'],$sql);
        return $query;
    }
    //发布技能
    public function getUnconfirmTask2($nenufish_user_id){
        $sql = "SELECT *
                FROM db_nenufish.db_nenufish_task,db_nenufish.db_nenufish_skillfind
                WHERE nenufish_task_offerUser = ".$nenufish_user_id." AND nenufish_task_state = '5' AND nenufish_task_skillofferId = nenufish_skillOffer_id";
        $query = mysqli_query($GLOBALS['link'],$sql);
        return $query;
    }

    //更改用户信息（头像、用户名）
    public function updateUser($nenufish_user_id,$nenufish_user_name,$nenufish_user_pic,$nenufish_user_updatePsw){
        $sql = "UPDATE db_nenufish.db_nenufish_user,db_nenufish.db_nenufish_skilloffer
                SET nenufish_user_name = '".$nenufish_user_name."',nenufish_user_pic = '".$nenufish_user_pic."',nenufish_user_psw = ".$nenufish_user_updatePsw."
                WHERE nenufish_user_id = ".$nenufish_user_id;
        $query = mysqli_query($GLOBALS['link'],$sql);
    }

    //更改用户提供技能信息（提供技能类型、提供技能状态）
    public function updateOfferSkill($nenufish_user_id,$nenufish_user_updateSkill,$nenufish_user_updateUserState){
        $sql = "UPDATE db_nenufish.db_nenufish_skilloffer
                SET nenufish_skillOffer_type = ".$nenufish_user_updateSkill." ,nenufish_skillOffer_editorState = ".$nenufish_user_updateUserState."
                WHERE nenufish_skillOffer_editor = ".$nenufish_user_id;
        $query = mysqli_query($GLOBALS['link'],$sql);
    }

    //任务确认
    //状态2（表示任务完成等待发布方确认）更新为状态3（表示发布方确认完毕等待发布方完成技能任务）
    public function confirmTask1($nenufish_user_taskId){
        $sql = "UPDATE db_nenufish.db_nenufish_task
                SET nenufish_task_state = '3'
                WHERE nenufish_task_state = '2' AND nenufish_task_id = ".$nenufish_user_taskId;
        $query = mysqli_query($GLOBALS['link'],$sql);
    }
    //状态5（表示发布方付款完毕或技能任务完成等待完成方确认 ）更新为状态6（表示任务结束 ）
    public function confirmTask2($nenufish_user_taskId){
        $sql = "UPDATE db_nenufish.db_nenufish_task
                SET nenufish_task_state = '6'
                WHERE nenufish_task_state = '5' AND nenufish_task_id = ".$nenufish_user_taskId;
        $query = mysqli_query($GLOBALS['link'],$sql);
    }

    //任务完成
    //状态1（表示任务进行中未完成 ）更新为状态2（表示任务完成等待发布方确认 ）
    public function completeTask1($nenufish_user_taskId){
        $sql = "UPDATE db_nenufish.db_nenufish_task
                SET nenufish_task_state = '2'
                WHERE nenufish_task_state = '1' AND nenufish_task_id = ".$nenufish_user_taskId;
        $query = mysqli_query($GLOBALS['link'],$sql);
    }
    //状态3（表示发布方确认完毕等待发布方完成技能任务 ）更新为状态5（表示发布方付款完毕或技能任务完成等待完成方确认 ）
    public function completeTask2($nenufish_user_taskId){
        $sql = "UPDATE db_nenufish.db_nenufish_task
                SET nenufish_task_state = '5'
                WHERE nenufish_task_state = '3' AND nenufish_task_id = ".$nenufish_user_taskId;
        $query = mysqli_query($GLOBALS['link'],$sql);
    }

    //支付（状态4（表示发布方确认完毕等待发布方付款 ）更新为状态5（表示发布方付款完毕或技能任务完成等待完成方确认 ））
    public function payTask($nenufish_user_taskId){
        $sql = "UPDATE db_nenufish.db_nenufish_task
                SET nenufish_task_state = '5'
                WHERE nenufish_task_state = '4' AND nenufish_task_id = ".$nenufish_user_taskId;
        $query = mysqli_query($GLOBALS['link'],$sql);
    }

    //登录判断
    public function login($nenufish_user_name){
        $sql = "SELECT nenufish_user_psw,nenufish_user_id
                FROM db_nenufish_user
                WHERE nenufish_user_name = '".$nenufish_user_name."'";
        $query = mysqli_query($GLOBALS['link'],$sql);
        return $query;
    }

    //注册查询id
    public function insertId($nenufish_user_name){
        $sql = "SELECT nenufish_user_id
                FROM db_nenufish.db_nenufish_user
                WHERE nenufish_user_name = ".$nenufish_user_name;
        $query = mysqli_query($GLOBALS['link'],$sql) ;
        return $query;
    }

    //注册查询是否存在用户名
    public function selectName($nenufish_user_name){
        $sql = "SELECT count(*)
                FROM db_nenufish_user
                WHERE nenufish_user_name = ".$nenufish_user_name;
        $query = mysqli_query($GLOBALS['link'],$sql) ;
        return $query;
    }
}
 ?>

